from rest_framework import serializers

# from School.models import SchoolNotification
from Student.models import *
from School.models import *


class StudentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Student
        fields = '__all__'


# class ApplicationSerializer(serializers.ModelSerializer):
#     name = serializers.CharField(source='stu.name', read_only=True)
#     st_sno = serializers.CharField(source='stu.sno', read_only=True)
#
#     class Meta:
#         model = Application
#         fields = ['id', 'name', 'status', 'school', 'application_date', 'application_content', 'stu', 'st_sno']


class SchoolSerializer(serializers.ModelSerializer):
    class Meta:
        model = School
        fields = '__all__'


class SchoolNotificationSerializer(serializers.ModelSerializer):
    class Meta:
        model = Notification
        fields = '__all__'


class ProofSerializer(serializers.ModelSerializer):
    class Meta:
        model = Proofs
        fields = ['url', 'description']


class ApplicationSerializer(serializers.ModelSerializer):
    student_name = serializers.PrimaryKeyRelatedField(queryset=Student.objects.all())
    name = serializers.CharField(source='student_name.name', read_only=True)
    proofs = ProofSerializer(many=True, required=False, source='img', read_only=True)

    class Meta:
        model = Application
        fields = ['id', 'student_name', 'name', 'requested_identity',
                  'reason', 'status', 'application_date', 'faculty',
                  'tags', 'reject_reason', 'proofs']  # 明确列出所有需要的字段


class NotificationSerializer(serializers.ModelSerializer):
    class Meta:
        model = Snotification
        fields = '__all__'


class SchoolApplicationSerializer(serializers.ModelSerializer):
    class Meta:
        model = SchoolApplication
        fields = '__all__'
